package cn.tedu.project.oa.assetRequisition.controller;

import cn.tedu.project.oa.assetRequisition.pojo.dto.AssetRequisitionQuery;
import cn.tedu.project.oa.assetRequisition.pojo.dto.AssetRequisitionSaveParam;
import cn.tedu.project.oa.assetRequisition.pojo.vo.AssetRequisitionVO;
import cn.tedu.project.oa.assetRequisition.service.AssetRequisitionService;
import cn.tedu.project.oa.base.response.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/oa/asset/requisition")
@Api(tags = "04.固定资产-领用资产")
public class AssetRequisitionController {

    @Autowired
    AssetRequisitionService assetRequisitionService;
    @PostMapping("save")
    @ApiOperation("领用资产申请+修改")
    public JsonResult saveRequisition(AssetRequisitionSaveParam assetRequisitionSaveParam){
        log.debug("新增领用资产单:assetRequisitionSaveParam={}",assetRequisitionSaveParam);

        assetRequisitionService.saveRequisition(assetRequisitionSaveParam);

        return JsonResult.ok();
    }

    @GetMapping("select")
    @ApiOperation("查询领用")
    public JsonResult selectRequisition(AssetRequisitionQuery assetRequisitionQuery){
        log.debug("查询领用资产列表:assetRequisitionQuery={}",assetRequisitionQuery);

        List<AssetRequisitionVO> list = assetRequisitionService.selectRequisition(assetRequisitionQuery);

        return JsonResult.ok(list);
    }

    @PostMapping("delete/{id}")
    @ApiOperation("删除领用")
    public JsonResult deleteById(@PathVariable Long id){
        log.debug("删除领用申请:id={}",id);

        assetRequisitionService.deleteById(id);

        return JsonResult.ok();
    }

    @PostMapping("update")
    @ApiOperation("更新审批")
    public JsonResult updateStatus(AssetRequisitionSaveParam assetRequisitionSaveParam){
        log.debug("更新审批状态:assetRequisitionSaveParam={}",assetRequisitionSaveParam);

        assetRequisitionService.updateStatusById(assetRequisitionSaveParam);

        return JsonResult.ok();
    }
}
